package com.quanxi.qxaimain.service.SDQueryService;

import com.quanxi.qxaimain.dao.SDQuery.SDQueryMapper;
import com.quanxi.qxaimain.dao.insertDemo.insertDemoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author lyx
 * @create 2022/11/28 17:48
 */
@Slf4j
@Service("ISDQueryResulService")
public class ISDQueryResulDemoServiceImpl   implements ISDQueryResulDemoService {

    @Resource
    private SDQueryMapper SDQueryMapper;

    @Autowired
     insertDemoMapper insertDemoMapper;


    @Override
    public void batchSDHandle() {

        String sql = "select * from TB_CIS_DRADVICE_DETAIL";
        SDQueryResultHandler sdQueryResultHandler = new SDQueryResultHandler() {
            @Override
            public void handle() {

                try {
                    log.info("---------------------:{}",list.size());
                    //list 批量查询结果集,对此list进行业务处理

                    insertDemoMapper.insert_TB_CIS_DRADVICE_DETAIL_COPY(list);

                } catch (Exception  e){
                    log.info(e.getMessage()+"===========error==========");
                }finally {
                    // 处理完每批数据后后将临时清空
                    size = 0;
                    list.clear();
                }

            }

            @Override
            public Map singlehandle(Map map) {
                   //处理每条数据
               //   log.info("---------------------:{}",map.get("DOC_ADV_DETAIL_NAME")+"9999999");
                  map.put("DOC_ADV_DETAIL_NAME","CleanFinish"+map.get("DOC_ADV_DETAIL_NAME"));
                    return map;
            }

            @Override
            public void tryFetchData() {
                SDQueryMapper.streamDataDynamicHandle(sql,this);
            }
        };

        sdQueryResultHandler.setBatchSize(1000); //设置批处理数
        sdQueryResultHandler.start();
        sdQueryResultHandler.lastSDHandle();// 批处理余数



    }



}